<html>
<head><meta charset="utf-8"><title>MIR: Why is TerminatorKind::Call.destination an Option? · t-compiler/help · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/index.html">t-compiler/help</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/MIR.3A.20Why.20is.20TerminatorKind.3A.3ACall.2Edestination.20an.20Option.3F.html">MIR: Why is TerminatorKind::Call.destination an Option?</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="217247253"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/MIR%3A%20Why%20is%20TerminatorKind%3A%3ACall.destination%20an%20Option%3F/near/217247253" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Robin Moussu <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/MIR.3A.20Why.20is.20TerminatorKind.3A.3ACall.2Edestination.20an.20Option.3F.html#217247253">(Nov 19 2020 at 09:48)</a>:</h4>
<p>I don't understand why <a href="https://doc.rust-lang.org/nightly/nightly-rustc/rustc_middle/mir/terminator/enum.TerminatorKind.html"><code>TerminatorKind::Call.destination</code></a> is an option. I thought that if a function was returning <code>()</code>, then the "return" value would just be stored in a local whose type is <code>()</code>. This <a href="https://play.rust-lang.org/?version=stable&amp;mode=release&amp;edition=2018&amp;gist=f83058a78201422f6c7af323d24eb1f2">little experiment</a> on the playground confirm my hypothesis (I copied the code just below). The <code>baz()</code> function have 3 locals, its own return value, and the return value of <code>foo()</code> and <code>bar()</code>. All three of them have type<code>()</code>.</p>
<div class="codehilite" data-code-language="Rust"><pre><span></span><code><span class="k">fn</span> <span class="nf">foo</span><span class="p">()</span><span class="w"> </span><span class="p">{}</span><span class="w"></span>
<span class="k">fn</span> <span class="nf">bar</span><span class="p">()</span><span class="w"> </span><span class="p">{}</span><span class="w"></span>
<span class="k">fn</span> <span class="nf">baz</span><span class="p">()</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">    </span><span class="n">foo</span><span class="p">();</span><span class="w"></span>
<span class="w">    </span><span class="n">bar</span><span class="p">();</span><span class="w"></span>
<span class="w">    </span><span class="p">()</span><span class="w"></span>
<span class="p">}</span><span class="w"></span>
</code></pre></div>
<p>Can I always unwrap the <code>destination</code>, or is there cases where this will fail (and why?)?</p>



<a name="217251542"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/MIR%3A%20Why%20is%20TerminatorKind%3A%3ACall.destination%20an%20Option%3F/near/217251542" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jonas Schievink  [he/him] <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/MIR.3A.20Why.20is.20TerminatorKind.3A.3ACall.2Edestination.20an.20Option.3F.html#217251542">(Nov 19 2020 at 10:34)</a>:</h4>
<p>It is None for diverging functions</p>



<a name="217253401"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/MIR%3A%20Why%20is%20TerminatorKind%3A%3ACall.destination%20an%20Option%3F/near/217253401" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Robin Moussu <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/MIR.3A.20Why.20is.20TerminatorKind.3A.3ACall.2Edestination.20an.20Option.3F.html#217253401">(Nov 19 2020 at 10:50)</a>:</h4>
<p>ehh! What is a diverging function?</p>



<a name="217253600"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/MIR%3A%20Why%20is%20TerminatorKind%3A%3ACall.destination%20an%20Option%3F/near/217253600" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lqd <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/MIR.3A.20Why.20is.20TerminatorKind.3A.3ACall.2Edestination.20an.20Option.3F.html#217253600">(Nov 19 2020 at 10:53)</a>:</h4>
<p>a function which doesn't return</p>



<a name="217253701"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/MIR%3A%20Why%20is%20TerminatorKind%3A%3ACall.destination%20an%20Option%3F/near/217253701" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Robin Moussu <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/MIR.3A.20Why.20is.20TerminatorKind.3A.3ACall.2Edestination.20an.20Option.3F.html#217253701">(Nov 19 2020 at 10:54)</a>:</h4>
<p>Ah, a function that "returns" <code>!</code>?</p>



<a name="217253721"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/MIR%3A%20Why%20is%20TerminatorKind%3A%3ACall.destination%20an%20Option%3F/near/217253721" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lqd <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/MIR.3A.20Why.20is.20TerminatorKind.3A.3ACall.2Edestination.20an.20Option.3F.html#217253721">(Nov 19 2020 at 10:54)</a>:</h4>
<p>things that loop forever or return <code>!</code></p>



<a name="217253793"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/MIR%3A%20Why%20is%20TerminatorKind%3A%3ACall.destination%20an%20Option%3F/near/217253793" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Robin Moussu <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/MIR.3A.20Why.20is.20TerminatorKind.3A.3ACall.2Edestination.20an.20Option.3F.html#217253793">(Nov 19 2020 at 10:55)</a>:</h4>
<p>got it, thanks</p>



<a name="217253825"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/MIR%3A%20Why%20is%20TerminatorKind%3A%3ACall.destination%20an%20Option%3F/near/217253825" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lqd <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/MIR.3A.20Why.20is.20TerminatorKind.3A.3ACall.2Edestination.20an.20Option.3F.html#217253825">(Nov 19 2020 at 10:55)</a>:</h4>
<p>mais de rien <span aria-label="baguette" class="emoji emoji-1f956" role="img" title="baguette">:baguette:</span></p>



<a name="217253923"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/MIR%3A%20Why%20is%20TerminatorKind%3A%3ACall.destination%20an%20Option%3F/near/217253923" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Robin Moussu <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/MIR.3A.20Why.20is.20TerminatorKind.3A.3ACall.2Edestination.20an.20Option.3F.html#217253923">(Nov 19 2020 at 10:56)</a>:</h4>
<p>What, my accent is so strong you can read it?!</p>



<a name="217253981"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/MIR%3A%20Why%20is%20TerminatorKind%3A%3ACall.destination%20an%20Option%3F/near/217253981" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lqd <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/MIR.3A.20Why.20is.20TerminatorKind.3A.3ACall.2Edestination.20an.20Option.3F.html#217253981">(Nov 19 2020 at 10:57)</a>:</h4>
<p>(nice use of english typography rules rather than french ones though :)</p>



<a name="217254091"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/MIR%3A%20Why%20is%20TerminatorKind%3A%3ACall.destination%20an%20Option%3F/near/217254091" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Robin Moussu <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/MIR.3A.20Why.20is.20TerminatorKind.3A.3ACall.2Edestination.20an.20Option.3F.html#217254091">(Nov 19 2020 at 10:58)</a>:</h4>
<p>I try, I try. Here is an unbreakable space <code> </code> in case you need one for your french typography!</p>



<a name="217254203"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/MIR%3A%20Why%20is%20TerminatorKind%3A%3ACall.destination%20an%20Option%3F/near/217254203" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lqd <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/MIR.3A.20Why.20is.20TerminatorKind.3A.3ACall.2Edestination.20an.20Option.3F.html#217254203">(Nov 19 2020 at 10:59)</a>:</h4>
<p>(en retour je te prête un point exclarrogatif ‽ :D)</p>



<a name="217256064"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/MIR%3A%20Why%20is%20TerminatorKind%3A%3ACall.destination%20an%20Option%3F/near/217256064" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Robin Moussu <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/MIR.3A.20Why.20is.20TerminatorKind.3A.3ACall.2Edestination.20an.20Option.3F.html#217256064">(Nov 19 2020 at 11:19)</a>:</h4>
<p><span class="user-mention" data-user-id="116113">@lqd</span>  Thanks (I was looking at the keymap of my bepo keyboard and noticed that I can’t write ‽ because my compose key isn’t mapped, and I’m using the 1.0 version of the keymap. <code>‽</code> was added in the afnor (1.1) version, and after some tests, it seems that my compose file isn't up-to date since the <code>dead_latin_bepo</code> doesn't work if I change my disposition to bepo_afnor. AKA, how to loose 20 minutes at looking at keyboard configuration!!!</p>



<a name="217256122"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/MIR%3A%20Why%20is%20TerminatorKind%3A%3ACall.destination%20an%20Option%3F/near/217256122" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Robin Moussu <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/MIR.3A.20Why.20is.20TerminatorKind.3A.3ACall.2Edestination.20an.20Option.3F.html#217256122">(Nov 19 2020 at 11:19)</a>:</h4>
<p>I have absolutely no idea of what I was doing before!</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>